using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine;

// 转换条件
public enum SoldierTransition
{
    NullTansition = 0,
    SeeEnemy,
    NoEnmey,
    CanAttack
}

// 状态类型ID
public enum SoldierStateID
{
    NullState,
    Idle,
    Chase,
    Attack
}
// 状态转换切换

// fsmSystem管理所有的状态
// 当前处于哪个状态
// 添加状态
// 删除状态
// 设置默认状态
// 发出Transition条件

// 士兵抽象状态接口
public abstract class ISoldierState
{
    // 字典存储所有的转换条件
    protected Dictionary<SoldierTransition, SoldierStateID> mTransitionDic =
        new Dictionary<SoldierTransition, SoldierStateID>();

    // 士兵当前状态ID
    protected SoldierStateID mStateID;

    public SoldierStateID stateID
    {
        get { return mStateID; }
    }

    protected ICharacter mCharacter; // 状态属于哪个士兵对象
    protected SoldierFSMSytem mFSM;

    public ISoldierState(SoldierFSMSytem fsm, ICharacter character)
    {
        mFSM = fsm;
        mCharacter = character; //?
    }


    public void AddTransition(SoldierTransition trans, SoldierStateID id)
    {
        if (trans == SoldierTransition.NullTansition)
        {
            Debug.LogError("SoldierState Error: trans不能为空");
            return;
        }

        if (id == SoldierStateID.NullState)
        {
            Debug.LogError("SoldierState Error: id状态ID不能为空");
            return; //?
        }

        if (mTransitionDic.ContainsKey(trans))
        {
            Debug.LogError("SoldierState" + trans + "SoldierState Error: 已经存在该转换条件");
            return;
        }

        mTransitionDic.Add(trans, id);
    }

    public void DeleteTransition(SoldierTransition trans)
    {
        if (mTransitionDic.ContainsKey(trans) == false)
        {
            Debug.LogError("删除转换条件的时候， 转换条件：[" + trans + "]不存在");
            return;
        }

        mTransitionDic.Remove(trans);
    }

    // 判断当前转换条件下，是否可以转换
    public SoldierStateID GetOutPutState(SoldierTransition trans)
    {
        if (mTransitionDic.ContainsKey(trans))
        {
            return mTransitionDic[trans];
        }

        return SoldierStateID.NullState;
    }

    public virtual void DoBeforeEntering()
    {
    }

    public virtual void DoBeforeLeaving()
    {
    }

    // 当前状态下是否需要转换到其他状态
    public abstract void Reason(List<ICharacter> targets);

    // 当前状态下需要执行的行为
    public abstract void Act(List<ICharacter> targets);
}